//
//  GLShowPickerView.h
//  KTools
//
//  Created by 121 on 2017/9/25.
//  Copyright © 2017年 杭州吉利控股信息中心. All rights reserved.
//


#import <UIKit/UIKit.h>
typedef NS_ENUM(NSInteger, GLPickerEvent) {
    GLPickerEventCancel = 10,
    GLPickerEventSure,
};


typedef NSString*(^GLPickerStringCovertBlock)(id model);
typedef void(^GLPickerCompetionBlock)(GLPickerEvent event,id value);

//多列

typedef NSString*(^GLPickerStringMutableCovertBlock)(id model,NSInteger component);
typedef void(^GLPickerMutableCompetionBlock)(GLPickerEvent event,NSArray* values);

//custompicker block
typedef NSInteger(^GLPickerNumOfComponentBlock)(UIPickerView* picker);
typedef NSInteger(^GLPickerNumOfRowsBlock)(UIPickerView* picker,NSInteger component);
typedef UIView*(^GLPickerTitleViewBlock)(UIPickerView* picker,NSInteger row,NSInteger component,UILabel* label);
typedef void(^GLPickerDidSelectRowBlock)(UIPickerView* picker,NSInteger row,NSInteger component);


@interface GLPickerView : UIView
@property(nonatomic,readonly)UIView *header;
@property(nonatomic,readonly)UIView *headerLine;
@property(nonatomic,readonly)UIButton *cancleBtn;
@property(nonatomic,readonly)UIButton *sureBtn;
@property(nonatomic,readonly)UILabel *titleLabel;
#pragma mark- data
//单列数据


/**
 单列数据选择器

 @param datas 数据数组
 @param convert 数据转换器，如果数组item不是NSString，需调用者转换，返回需要显示的字符，如item为一个model，需返回model.name
 @param competion 选择结果调用，需先判断event是取消事件还是点击确定事件，value为数组item
 */
+ (instancetype)showDatas:(NSArray*)datas convert:(GLPickerStringCovertBlock)convert competion:(GLPickerCompetionBlock)competion;

//多列数据


/**
 多列数据选择器

 @param datas 数据数组
 @param component 需要显示的列数
 @param keys 返回子列数组的key值
 @param convert 数据转换器，如果数组item不是NSString，需调用者转换，返回需要显示的字符，如item为一个model，需返回model.name
 @param competion 选择结果调用，需先判断event是取消事件还是点击确定事件，value为数组
 */
+ (instancetype)showDatas:(NSArray*)datas component:(NSInteger)component subArrayKey:(NSArray*)keys  convert:(GLPickerStringMutableCovertBlock)convert competion:(GLPickerMutableCompetionBlock)competion;

/**
 多列数据选择器

 @param datas 数据数组
 @param component 需要显示的列数
 @param weights 每列显示宽度的权重数组，如3列，宽度为1:2:3则传值@[@1,@2,@3]
 @param keys 返回子列数组的key值
 @param convert 数据转换器，如果数组item不是NSString，需调用者转换，返回需要显示的字符，如item为一个model，需返回model.name
 @param competion 选择结果调用，需先判断event是取消事件还是点击确定事件，value为数组
 */
+ (instancetype)showDatas:(NSArray*)datas component:(NSInteger)component weights:(NSArray*)weights subArrayKey:(NSArray*)keys  convert:(GLPickerStringMutableCovertBlock)convert competion:(GLPickerMutableCompetionBlock)competion;
#pragma mark- noLikeageData

/**
 多列数据选择器
 
 @param datas 数据数组 @[@[...],@[...],@[...]]
 @param component 需要显示的列数
 @param weights 每列显示宽度的权重数组，如3列，宽度为1:2:3则传值@[@1,@2,@3]
 @param convert 数据转换器，如果数组item不是NSString，需调用者转换，返回需要显示的字符，如item为一个model，需返回model.name
 @param competion 选择结果调用，需先判断event是取消事件还是点击确定事件，value为数组
 */
+ (instancetype)showNoLinkageDatas:(NSArray*)datas component:(NSInteger)component weights:(NSArray*)weights convert:(GLPickerStringMutableCovertBlock)convert competion:(GLPickerMutableCompetionBlock)competion;


+ (instancetype)showCustomePickerByWeights:(NSArray*)weights numOfComponent:(GLPickerNumOfComponentBlock)numOfComponent numOfRows:(GLPickerNumOfRowsBlock)numOfRows titleView:(GLPickerTitleViewBlock)configView didSelected:(GLPickerDidSelectRowBlock)selectedBlock competion:(GLPickerCompetionBlock)competion;
@end




typedef NS_ENUM(NSInteger, GLDatePickerMode) {
    GLDatePickerModeYear, //年
    GLDatePickerModeYearAndMonth, //年 月
    GLDatePickerModeDate, //年 月 日
    GLDatePickerModeDateHourMinute, //年 月 日 时 分
    GLDatePickerModeDateHourMinuteSecond, //年 月 日 时 分 秒
    GLDatePickerModeTime, //时 分
    GLDatePickerModeTimeAndSecond, //时 分 秒
    GLDatePickerModeMaxNumber,
};

typedef NS_ENUM(NSInteger, GLDatePickerTime) {
    GLDatePickerTimeYear = NSCalendarUnitYear,
    GLDatePickerTimeMonth = NSCalendarUnitMonth,
    GLDatePickerTimeDay = NSCalendarUnitDay,
    GLDatePickerTimeHour = NSCalendarUnitHour,
    GLDatePickerTimeMinute = NSCalendarUnitMinute,
    GLDatePickerTimeSecond = NSCalendarUnitSecond,
};

typedef void(^GLDatePickerCompetionBlock)(GLPickerEvent event,NSDateComponents* value);


@interface GLDatePickerView : GLPickerView
+ (NSDate *)setYear:(NSInteger)year month:(NSInteger)month day:(NSInteger)day hour:(NSInteger)hour minute:(NSInteger)minute second:(NSInteger)second ;
+ (NSDate *)setYear:(NSInteger)year month:(NSInteger)month day:(NSInteger)day;
+ (NSDateComponents *)dateComponentsForDate:(NSDate*)date;
/**
 日期选择器
 
 @param mode 同UIDatePicker
 @param competion 选择结果调用，需先判断event是取消事件还是点击确定事件，value为NSDate
 */
+ (instancetype)showDate:(GLDatePickerMode)mode competion:(GLDatePickerCompetionBlock)competion;
+ (instancetype)showDate:(GLDatePickerMode)mode minDate:(NSDate*)minDate maxDate:(NSDate*)maxDate selectdDate:(NSDate*)date competion:(GLDatePickerCompetionBlock)competion;


@end
